package com.dzt.androidframework.express;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.ActivityTitle;
import com.dzt.androidframework.eventbus.EventBusUtil;
import com.dzt.androidframework.express.javabean.OrderEvent;
import com.dzt.androidframework.fragment.FragmentBase;
import com.dzt.androidframework.fragment.FragmentTabAdapter;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 快递查询功能是根据快递100（http://www.kuaidi100.com/）提供的API来实现的
 */
public class ExpressActivity extends ActivityTitle {

	@ViewInject(R.id.bottom_tab_container)
	private RadioGroup mTabContainer;
	private List<FragmentBase> mTabFragments;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_express;
	}

	@Override
	protected void initParams() {
		setTitleView(R.string.query);
		titleView.setRightClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				TextView tv = (TextView) view;
				if ("编辑".equals(tv.getText().toString())) {
					tv.setText("取消");
					EventBusUtil.postSync(new OrderEvent(false, false, "ExpressActivity", -1, this));
				} else if ("取消".equals(tv.getText().toString())) {
					tv.setText("编辑");
					EventBusUtil.postSync(new OrderEvent(true, false, "ExpressActivity", -1, this));
				}
			}
		});
		mTabContainer.getChildAt(0).performClick();
		mTabFragments = new ArrayList<>();
		mTabFragments.add(new FragmentHome());
		mTabFragments.add(new FragmentBill());
		mTabFragments.add(new FragmentMine());
		FragmentTabAdapter mTabAdapter = new FragmentTabAdapter(getSupportFragmentManager(),
				mTabFragments, R.id.fragments_container, mTabContainer);
	}

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	@Event(value = {R.id.rb_home, R.id.rb_bill, R.id.rb_mine})
	private void onViewClick(View v) {
		switch (v.getId()) {
			case R.id.rb_home:
				titleView.setCenterDetail(R.string.query);
				titleView.setRightDetailInvisible();
				break;
			case R.id.rb_bill:
				titleView.setCenterDetail(R.string.order_state);
				titleView.setRightDetail("编辑");
				break;
			case R.id.rb_mine:
				titleView.setCenterDetail(R.string.mine);
				titleView.setRightDetailInvisible();
				break;
			default:
				break;
		}
	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}
}
